package com.university.report.user.config;

import com.university.report.common.constant.RabbitMQConst;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName health_report
 * @Author Jinondo
 * @Date 2021/6/18 14:10
 */
@Configuration
public class RabbitMqConfiguration{

    /**
     *  声明 Direct 交换机
     * @return
     */
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange(RabbitMQConst.DIRECT_EXCHANGE,true,false);
    }

    /**
     * 声明队列
     * @return
     */
    @Bean
    public Queue reportQueue(){
        return new Queue(RabbitMQConst.REPORT_QUEUE,true);
    }

    /**
     * 完成绑定关系
     * @return
     */
    @Bean
    public Binding smsBinding(){
        return BindingBuilder.bind(reportQueue()).to(directExchange()).with(RabbitMQConst.REPORT_KEY);
    }

}
